﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using CoursePack;

namespace WindowsFormsApplication2
{
    public partial class Login : Form
    {

        #region Constructors
        public Login()
        {
            InitializeComponent();
        }
        #endregion

        private void Login_Load(object sender, EventArgs e)
        {

            

        }

        #region Buttons Events 

        private void btnCancel_Click(object sender, EventArgs e)
        {
            //Close the application
            this.Close();
        }
      

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string User = this.textBox1.Text;
            string Password = this.textBox2.Text;

            //Open the file containing student information
            Stream stream = File.Open("Student.osl", FileMode.Open);
            BinaryFormatter bformatter = new BinaryFormatter();



            Console.WriteLine("Reading Employee Information");
            Student student = (Student)bformatter.Deserialize(stream);
            stream.Close();

            if (User == student.NetName && student.IsValidPassword(Password))
            {
                // Open student home page
                Forms.HomePage frm = new Forms.HomePage(student);
                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {

                }
            }
            else
                this.lblStatus.Text = " Your NetName and/or password is invalid";

        }

        private void lblNotRegistered_Click(object sender, EventArgs e)
        {
            // Open student registration form
            Forms.frmRegister frm = new Forms.frmRegister();
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

            }
        }
        #endregion

    }
}
